package crm.view.Admin;

import crm.Utils.RoundBorder;
import crm.dao.impl.CustomerSqlSeverImpl;
import crm.dao.impl.EmployeeSqlSeverImpl;
import crm.entity.Customer;
import crm.entity.Employee;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

/**
 * 查询功能：
 * 统计员工业绩信息
 */

public class QueryPerformance implements ActionListener {
    JFrame frame = null;
    JButton btn1 = null;


    JLabel label = null;
    JLabel label1 = null;
    JTextField field = null;

    public static void main(String[] args) {
        new QueryPerformance();
    }

    public QueryPerformance() {
        init();
        frame.setBounds(480, 280, 650, 500);

        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setVisible(true);
    }

    public void init() {
        frame = new JFrame("统计员工业绩信息");
        btn1 = new JButton("开始查询");
        label1 = new JLabel("输入客户姓名：");
        field = new JTextField();



        JPanel panel = new JPanel();
        panel.setLayout(null);

        label1.setBounds(100, 100, 250, 50);
        field.setBounds(330, 100, 200, 50);
        btn1.setBounds(250, 170, 100, 45);


        label = new JLabel("统计员工业绩信息");
        label.setFont(new Font("Dialog", 1, 30));
        label.setBounds(200, 20, 300, 60);



        //加载图片
        ImageIcon icon = new ImageIcon("src/img/2223.png");
        //Image im=new Image(icon);
        //将图片放入label中
        JLabel imgLabel = new JLabel(icon);
        //设置label的大小
        imgLabel.setBounds(150, 200, icon.getIconWidth(), icon.getIconHeight());

        Font font1 = new Font("宋体", Font.BOLD, 30);
        label1.setFont(font1);
        field.setFont(font1);
        panel.add(label);
        frame.add(btn1);
        panel.add(imgLabel);
        frame.add(panel);
        panel.add(label1);
        panel.add(field);
        btn1.setOpaque(false);// 设置原来按钮背景透明
        btn1.setBorder(new RoundBorder());
        btn1.setBorder(new RoundBorder(Color.PINK));
        btn1.addActionListener(this);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        Employee employee = new Employee();
        EmployeeSqlSeverImpl dao = new EmployeeSqlSeverImpl();
        String name = field.getText();
        if ("".equals(field.getText())) {
            JOptionPane.showMessageDialog(null,"请输入用户姓名！");
        } else if ("开始查询".equals(e.getActionCommand())) {
            List<Employee> employeeList = null;
            employeeList = dao.getByName(name);
            new EmployeePerformance(employeeList);
            frame.dispose();
        }
    }

}